package cn.alise.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 写文件
 *
 */
public class WriteFile {
	
	protected static final Log logger = LogFactory.getLog(WriteFile.class);
	
	/**
	 * 写文件
	 * @param path
	 * @param b
	 * @throws IOException 
	 */
	public static void write(String path, byte[] b) throws IOException {
		FileOutputStream os = null;
		
		try {
			os = new FileOutputStream(new File(path));
			os.write(b);
			
		} catch (IOException e) {
			logger.error("写文件失败，原因：" + e.getMessage(), e);
			throw e;
	    } catch (Exception e) {
	    	logger.error("写文件失败，原因：" + e.getMessage(), e);
	    	throw e;
	    } finally {
	    	 try {
				os.close();
			} catch (IOException e) {
				logger.error("关闭文件输出流失败，原因：" + e.getMessage(), e);
				throw e;
			}
	    }
	}
}
